<?php
/**
 * Created by inline.
 * User: swb
 * Date: 2022-10-31
 * Time: 11:00
 */
namespace app\store\controller\api\v1;
use library\Controller;
use app\common\controller\BaseApiController;
use app\common\facade\Token;
use app\common\model\SystemUser;
use app\shop\model\ShopOrder;
use app\common\model\User;
// use app\shop\model\ShopOrder;

class Index extends BaseApiController
{
    public function getIndex(){
        $uid = $this->request->param('id');
        $res = SystemUser::where('id',$uid)->with('store')->find();
        $this->successCode($res);
    }
    
    public function getPlatform(){
        $store_id = $this->request->param('store_id');
        $today_order = ShopOrder::where('store_id',$store_id)->where('is_pay',1)->whereNotIn('status','6,7')->whereTime('create_at', 'today')->count();
        $today_price = ShopOrder::where('store_id',$store_id)->where('is_pay',1)->whereNotIn('status','6,7')->whereTime('create_at', 'today')->sum('goods_price');
        $yestd_order = ShopOrder::where('store_id',$store_id)->where('is_pay',1)->whereNotIn('status','6,7')->whereTime('create_at', 'yesterday')->count();
        $yestd_price = ShopOrder::where('store_id',$store_id)->where('is_pay',1)->whereNotIn('status','6,7')->whereTime('create_at', 'yesterday')->sum('goods_price');
        $all_order = ShopOrder::where('store_id',$store_id)->where('is_pay',1)->whereNotIn('status','6,7')->count();
        $all_price = ShopOrder::where('store_id',$store_id)->where('is_pay',1)->whereNotIn('status','6,7')->sum('goods_price');
        $all_user = User::where('store_id',$store_id)->count();
        $month_user = User::where('store_id',$store_id)->whereTime('create_at', 'month')->count();
        $data = [
             'today_order'=>$today_order,
             'today_price'=>$today_price,
             'yestd_order'=>$yestd_order,
             'yestd_price'=>$yestd_price,
             'all_order'=>$all_order,
             'all_price'=>$all_price,
             'all_user'=>$all_user,
             'month_user'=>$month_user
        ];
        $this->successCode($data); 
    }
    
}